package com.lihegang.example;

import com.lihegang.example.util.filter.CustomFilter;
import com.lihegang.example.util.listener.CustomListener;
import com.lihegang.example.util.servlet.CustomServlet;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ImportResource;
import org.springframework.jms.annotation.EnableJms;

import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet;

@EnableRabbit
@EnableJms
@EnableCaching
@ServletComponentScan // 注入servelet中用
@ImportResource(locations = { "classpath:druid-bean.xml" })
@SpringBootApplication
public class SpringBootDemo21Application implements ServletContextInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws
            ServletException {
        servletContext.addServlet("customServlet", new
                CustomServlet()).addMapping("/api");
        servletContext.addFilter("customFilter", new
                CustomFilter())
                .addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "customServlet");
        servletContext.addListener(new CustomListener());
    }
    public static void main(String[] args) {
		SpringApplication.run(SpringBootDemo21Application.class, args);
	}
}
